package com.ruoyi.gxs.service.impl;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.gxs.mapper.GxsComprehensiveMapper;
import com.ruoyi.gxs.domain.GxsComprehensive;
import com.ruoyi.gxs.service.IGxsComprehensiveService;

/**
 * 我的综合得分Service业务层处理
 * 
 * @author 高晓松
 * @date 2024-01-03
 */
@Service
public class GxsComprehensiveServiceImpl implements IGxsComprehensiveService 
{
    @Autowired
    private GxsComprehensiveMapper gxsComprehensiveMapper;

    /**
     * 查询我的综合得分
     * 
     * @param gxsAppraisalid 我的综合得分主键
     * @return 我的综合得分
     */
    @Override
    public GxsComprehensive selectGxsComprehensiveByGxsAppraisalid(Long gxsAppraisalid)
    {
        return gxsComprehensiveMapper.selectGxsComprehensiveByGxsAppraisalid(gxsAppraisalid);
    }

    /**
     * 查询我的综合得分列表
     * 
     * @param gxsComprehensive 我的综合得分
     * @return 我的综合得分
     */
    @Override
    public List<GxsComprehensive> selectGxsComprehensiveList(GxsComprehensive gxsComprehensive)
    {
        List<GxsComprehensive> list = gxsComprehensiveMapper.selectGxsComprehensiveList(gxsComprehensive);
        for (GxsComprehensive comprehensive : list) {
            comprehensive.setGxsAppraisalScore(comprehensive.getGxsSchoolrecord()+
                    comprehensive.getGxsThought()+comprehensive.getGxsSportsscore());
        }

        // 使用自定义比较器根据age字段进行排序
        Collections.sort(list, new Comparator<GxsComprehensive>() {
            @Override
            public int compare(GxsComprehensive c1, GxsComprehensive c2) {
                return (int) (c2.getGxsAppraisalScore() - c1.getGxsAppraisalScore());
            }
        });
        return list;
    }

    /**
     * 新增我的综合得分
     * 
     * @param gxsComprehensive 我的综合得分
     * @return 结果
     */
    @Override
    public int insertGxsComprehensive(GxsComprehensive gxsComprehensive)
    {
        gxsComprehensive.setCreateTime(DateUtils.getNowDate());
        return gxsComprehensiveMapper.insertGxsComprehensive(gxsComprehensive);
    }

    /**
     * 修改我的综合得分
     * 
     * @param gxsComprehensive 我的综合得分
     * @return 结果
     */
    @Override
    public int updateGxsComprehensive(GxsComprehensive gxsComprehensive)
    {
        gxsComprehensive.setUpdateTime(DateUtils.getNowDate());
        return gxsComprehensiveMapper.updateGxsComprehensive(gxsComprehensive);
    }

    /**
     * 批量删除我的综合得分
     * 
     * @param gxsAppraisalids 需要删除的我的综合得分主键
     * @return 结果
     */
    @Override
    public int deleteGxsComprehensiveByGxsAppraisalids(Long[] gxsAppraisalids)
    {
        return gxsComprehensiveMapper.deleteGxsComprehensiveByGxsAppraisalids(gxsAppraisalids);
    }

    /**
     * 删除我的综合得分信息
     * 
     * @param gxsAppraisalid 我的综合得分主键
     * @return 结果
     */
    @Override
    public int deleteGxsComprehensiveByGxsAppraisalid(Long gxsAppraisalid)
    {
        return gxsComprehensiveMapper.deleteGxsComprehensiveByGxsAppraisalid(gxsAppraisalid);
    }
}
